package com.example.eldersystem.operatedata.service;

import com.example.eldersystem.operatedata.model.Event;
import com.example.eldersystem.response.DataResponse;
import com.example.eldersystem.operatedata.mapper.DetectorMapper;
import com.example.eldersystem.operatedata.model.Detector;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DetectorService {
    private DetectorMapper detectorMapper;

    @Autowired
    public void setDetectorMapper (DetectorMapper detectorMapper) {
        this.detectorMapper = detectorMapper;
    }


    public DataResponse<String> addDetector(Detector detector){
        DataResponse<String> dataResponse = new DataResponse<>();

        if(detectorMapper.addDetector(detector)>0){
            dataResponse.setMsg("添加摄像头成功");
        }else {
            dataResponse.setCode(181);
            dataResponse.setMsg("添加摄像头失败");
        }

        return dataResponse;
    }

    public DataResponse<List<Detector>> selectDetector(){
        DataResponse<List<Detector>> dataResponse = new DataResponse<>();
        List<Detector> list;
        int total = detectorMapper.selectDetectorNum();
        if(total<=0){
            dataResponse.setCode(10);
            dataResponse.setMsg("查询无结果");
        }else{
            dataResponse.setMsg("查询成功");
            list = detectorMapper.selectDetector();
            dataResponse.setData(list);
        }
        return dataResponse;
    }
}
